function [hax] = plot_witherror(t, v, verr, ib, title, xtick, symbol, color)
% plot data t and v, with standard error bars verr
% call: plot_witherror(t, v, verr, ib, title, xtick)
% t and v are the data and error arrays
% ib is the baseline index list (which points of t and v are used to make the
% baseline and the stdbars) as line and +/- limits.
% Paul B. Manis, Ph.D. 2002, revised as separate routine 7/2006
%
if(nargin < 7)
    color = 'k';
end;
if(nargin < 8)
    symbol = 'o';
end;
if(nargin < 6)
    xtick = 2;
end;

sym = [color symbol];
if(any(~isnan(v)))
    if(nargin > 3)
        [vm, vvar] = mean_var(v(ib));
        vvar = sqrt(vvar); % convert variance to SEM
    end;
    if(any(verr) > 0)
        my_errorbar(t, v, verr, verr, sym, (max(t)-min(t))/(100*length(t)));
    end;
    hold on;
    hplot = plot(t, v, sym);
    set(hplot, 'Markersize', 1.5, 'MarkerFaceColor', color, 'markeredgecolor', color);
    hold on;
    %set(hplot, 'color', 'black');
    %plot(t, v, 'Color', 'black', ...
    %'Marker', 'o', 'MarkerFaceColor', 'k', 'MarkerSize', 1.5, 'LineStyle', 'none')
    %set(gca, 'Xlim', [-1 50]);
    u = [0 max(t)];
    if(nargin > 3) % only plot the baseline info if it is specified
        plot(u, [vm vm], 'linestyle', '-', 'color', color);
        plot(u, [vm+vvar vm+vvar], 'linestyle', '--', 'color', color);
        plot(u, [vm-vvar vm-vvar], 'linestyle', '--', 'color', color);
    end;
    % u = get(gca, 'Ylim');
    % set(gca, 'Xlim', [-1 50]);
    % set(gca, 'Ylim', [u(1) u(2)]);
    hold off;
    if(nargin > 4) % only if specified
        ylabel(sprintf(title), 'Fontsize', 8, 'interpreter', 'tex');
    end;
    xlabel('time (min)', 'Fontsize', 8);
    hax = gca; % return handle to axes
    if(nargin < 5)
        set(gca,'XTick',[ ]);
    end;
    return
end;
